<div class='nextprev'>
  {{ if not .IsHome }}
    {{ if not .Parent.IsHome }}
      {{ $pages := .Parent.Pages }}
      {{ range where .Parent.Translations "Lang" "en" }}
        {{ $pages = $pages | lang.Merge .Pages }}
      {{ end }}

      {{ $self := .}}
      {{ $selfIdx := -1 }}
      {{ range $idx, $page := $pages }}
        {{ if eq $page $self }}
          {{ $selfIdx = $idx }}
        {{ end }}
      {{ end }}

      {{ if .IsSection }}
        <div class='left'>
        {{ with index $pages (add $selfIdx -1) }}
          {{ with index (last 1 .Pages) 0 }}
            <a href='{{.Permalink}}' id='prev-article'>← {{ .Title }}</a><br>
          {{ end }}
          <a href='{{.Permalink}}'>← ../{{ .Title }}</a>
        {{ end }}
        </div>
        <div class='right'>
        {{ with index .Pages 0 }}
          <a href='{{.Permalink}}' id='next-article'>{{ .Title }} →</a><br>
        {{ end }}
        {{ with index $pages (add $selfIdx 1) }}
          <a href='{{.Permalink}}'>../{{ .Title }} →</a>
        {{ end }}
        </div>
      {{ else }}
        <div class='left'>
        {{ with index $pages (add $selfIdx -1) }}
          <a href='{{.Permalink}}' id='prev-article'>← {{ .Title }}</a>
        {{ else }}
          <a href='{{.Parent.Permalink}}' id='prev-article'>← ../{{ .Parent.Title }}</a>
        {{ end }}
        </div>
        <div class='right'>
        {{ with index $pages (add $selfIdx 1) }}
          <a href='{{.Permalink}}' id='next-article'>{{ .Title }} →</a>
        {{ else }}
          {{ $parent := .Parent }}
          {{ $parentIdx := -1 }}
          {{ $pages = .Parent.Parent.Pages }}

          {{ range $idx, $page := $pages }}
            {{ if eq $page $parent }}
              {{ $parentIdx = $idx }}
            {{ end }}
          {{ end }}
        
          {{ with index $pages (add $parentIdx 1) }}
            <a href='{{.Permalink}}' id='next-article'>../{{ .Title }} →</a>
          {{ end }}
        {{ end }}
        </div>
      {{ end }}
    {{ end }}
  {{ end }}
</div>
